package com.yunsom.testdemo.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Author:Cxb
 * Description:判断字符串类型
 */

public class StringUtil {
  static final Pattern PATTERN = Pattern.compile("^[-+]?[\\d]*$");

  /**
   *  判断字符串是否为纯数字
   * @param str
   * @return true为是，false为不是
   */
  public static boolean isInteger(String str) {
    boolean result = PATTERN.matcher(str).matches();
    if(str.startsWith("0")||str.length()>6) {
      return false;
    }
    return result;
  }

  public static String humpToLine(String str) {
    Pattern humpPattern = Pattern.compile("[A-Z]");
    Matcher matcher = humpPattern.matcher(str);
    StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
      matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
    }
    matcher.appendTail(sb);
    return sb.toString();
  }

  /**
   * 根据某个符号分行打印文本
   */
  public static void printText(String text, String symbol){
    final String[] split = text.split(symbol);
    for (String s : split) {
      System.out.println(s);
    }
  }

}
